Skip to content

fallback: match the C extension's strict_map_key error message - #754

Open
Vansh8803 wants to merge 1 commit into
msgpack:mainfrom
Vansh8803:fallback/match-c-strict-map-key-message
Open

Vansh8803 wants to merge 1 commit into
msgpack:mainfrom
Vansh8803:fallback/match-c-strict-map-key-message

Conversation

@Vansh8803

Copy link
Copy Markdown

Summary

The pure-Python fallback and the C extension raise different error messages when a
map key has a type that strict_map_key disallows.

The C extension raises:

ValueError: int is not allowed for map key when strict_map_key=True

The pure-Python fallback raises:

ValueError: <class 'int'> is not allowed for map key

So the message a caller sees depends on whether the C extension is available, which
makes it unreliable to log, match, or assert on. This aligns the fallback with the C
extension: it now uses type(key).__name__ instead of str(type(key)) and includes
the same when strict_map_key=True suffix, so both backends report the identical error.

Changes

  • msgpack/fallback.py: use the same message as unpack_callback_map_item in
    unpack.h, in both the dict and object_pairs_hook map paths.
  • test/test_except.py: add test_strict_map_key_error_message, which asserts the
    message and runs under both the C extension and the fallback.

Notes

No behavior change beyond the message text. The full suite passes under both backends
(MSGPACK_PUREPYTHON=1 and the compiled extension).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant